#!/bin/bash

#get this script real directory
SOURCE="$0"
while [ -h "$SOURCE"  ]; do # resolve $SOURCE until the file is no longer a symlink
    this_script_dir="$( cd -P "$( dirname "$SOURCE"  )" && pwd  )"
    SOURCE="$(readlink "$SOURCE")"
    # if $SOURCE was a relative symlink, 
    #we need to resolve it relative to the path 
    #where the symlink file was located
    [[ $SOURCE != /*  ]] && SOURCE="$this_script_dir/$SOURCE"
done
this_script_dir="$( cd -P "$( dirname "$SOURCE"  )" && pwd  )"

source $this_script_dir/global.sh

which expect > /dev/null
if [ $? -ne 0 ] ; then
    vlogw "not found dependence \"expect\""
    vlogi "will install \"expect\""
else
    exit 0;
fi

_cur_dir=`pwd`

expect_src_dir=$this_script_dir/dependence

cd $expect_src_dir

tar -zxf tcl8.6.9-src.tar.gz
cd tcl8.6.9/unix && ./configure --prefix=$HOME/git/run
make && make install
rm -r tcl8.6.9 


cd $expect_src_dir
tar -zxf expect5.45.4.tar.gz
cd expect5.45.4
./configure --prefix=$HOME/git/run --with-tcl=$HOME/git/run/lib  --libdir=$HOME/git/run/lib --includedir=$HOME/git/run/include  --docdir=$HOME/git/run/man --mandir=$HOME/git/run/man   --oldincludedir=$HOME/git/run/include

make && make install

cp  $HOME/git/run/lib/expect5.45.4/* $HOME/git/run/lib/
cp  $this_script_dir/vlogin.sh $HOME/git/run/bin

source $this_script_dir/insert_profile.sh
insert_profile PATH $HOME/git/run/bin 0
insert_profile LD_LIBRARY_PATH $HOME/git/run/lib 0
echo "-- info,install expect OK."
exit 0
